<template>
  <div>
    <el-row style="margin-bottom:20px;display:flex;justify-content:flex-start">
      <el-input placeholder="维修/保养编号" style="width:20%;margin-right:10px" v-model="carrepairno" clearable></el-input>
      <el-input placeholder="牌照" style="width:20%;margin-right:10px" v-model="carno" clearable></el-input>
      <!--
      <selectcarnumber
        placeholder="牌照"
        @getpersonid2="getpersonid2"

        :itemtype="2"
        style="width:20%;margin-right:10px"
      ></selectcarnumber>
      -->
      <el-input placeholder="办理人" style="width:20%;margin-right:10px" v-model="holder" clearable></el-input>
      <!-- <searchperson @getpersonid="getpersonid" style="width:20%;margin-right:10px"></searchperson> -->
      <el-select v-model="repairtype" placeholder="请选择项目类型" style="margin-right:10px" clearable>
        <el-option v-for="item in itemdata" :key="item.value" :label="item.hash.code_name" :value="item.hash.code_id"></el-option>
      </el-select>
      <el-date-picker v-model="repairtime" style="width:32%;margin-right:20px" type="daterange" rangeSeparator="至"
        startPlaceholder="维修开始日期" endPlaceholder="维修结束日期" valueFormat="yyyy-MM-dd" placeholder="维修时间"
        clearable
      >
      </el-date-picker>
      <!-- <el-date-picker
        v-model="repairtime"
        type="date"
        value-format="yyyy-MM-dd"
        style="margin-right:10px"
        placeholder="维修时间"
      ></el-date-picker> -->

      <el-button size="mini" type="primary" @click="getweixiulist">搜索</el-button>
    </el-row>

    <el-row>
      <el-button size="mini" @click="addmain">添加维修/保养信息</el-button>
      <el-button size="mini" type="primary" @click="carmainedit">编辑</el-button>
      <el-button size="mini" type="success" @click="deletemain">删除</el-button>
    </el-row>
    <el-divider></el-divider>
    <maintaintable v-if="istrue" :tableData="carweixiulist" :pagobj.sync="pagobj" :itemval1.sync="itemval1"></maintaintable>
    <addmaintain :itemdata="itemdata" v-if="isaddmain" :chouseval="itemval1" @addmaintains="changezt"
      :chousebtn="btnvalue"
    ></addmaintain>
  </div>
</template>

<script>
import addmaintain from '~/components/carmanager/carmaintain/addmaintain.vue';
import maintaintable from '~/components/carmanager/carmaintain/maintaintable.vue';
import searchperson from '~/components/common/searchperson.vue';
import selectcarnumber from '~/components/common/selectcarnumber.vue';

export default {
  components: {
    maintaintable,
    addmaintain,
    searchperson,
    selectcarnumber,
  },
  data() {
    return {
      ts: this.newStore(),
      dialogVisible: false,
      isaddmain: false,
      pagesize: 0,
      currentPage: 0,
      istrue: true,
      addmaintain: {},
      carweixiulist: [],
      itemval1: [],
      // 分页
      pagobj: {
        currentPage3: 1,
        pagesize: 10,
        total: 10,
      },
      holder: '', // 办理人
      carrepairid: [], // 选中的数组id
      btnvalue: 0, // 判断按钮是添加还是编辑

      itemdata: [], // 项目类型
      // 传的数据
      carrepairno: '', // 维修编号
      carno: '', // 车牌号
      repairtype: '', // 维修类型
      repairtime: ['', ''], // 维修事件
      carholder: '', // 办理人
    };
  },
  created() {
    this.getweixiulist();
    this.getitem();
  },
  watch: {
    // changezt () {
    //   console.log(this);
    //   this.getweixiulist();
    //   this.reload('getweixiulist');
    // },

  },
  methods: {
    changezt() {
      this.getweixiulist();
    },
    // 获取cardno
    getpersonid2(val) {
      // this.carid = val.id;
      this.carno = val.id;
    },
    // 编辑
    carmainedit() {
      this.btnvalue = 2;
      // this.reload("isaddmain");
      if (this.itemval1.length == 1) {
        this.reload('isaddmain');
      } else if (this.itemval1.length == 0) {
        this.$message('请先勾选一个维修/保养信息');
      } else {
        this.$message('只能选择一个维修/保养信息');
      }
    },
    // 删除
    deletemain() {
      if (this.itemval1.length > 0) {
        this.$confirm(`是否删除${this.itemval1.length}条车辆维修信息?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }).then(() => {
          for (let i = 0; i < this.itemval1.length; i += 1) {
            this.carrepairid.push(this.itemval1[i].hash.carrepairid);
          }
          const req = {
            handle:
              '0E56125B90D2898AD5AF2EB92B0B60511870E6A44E4EFDA4BFF0B9210751F692',
            carrepairid: this.carrepairid,
          };
          this.spost(this.ts, '/mainservlet', req).then((ts) => {
            if (ts.d.sflag == 'success') {
              this.$message({
                type: 'success',
                message: '删除成功!',
              });
              this.getweixiulist();
            }
          });
        });
      } else {
        this.$message('请选择删除信息');
      }
    },
    // 公共组件刷新
    reload(partsname) {
      // console.log(partsname);

      this[partsname] = false;
      this.$nextTick(() => {
        this[partsname] = true;
      });
    },
    // 点击添加车辆
    addmain() {
      this.btnvalue = 1;
      this.reload('isaddmain');
    },
    // 获取负责人
    getpersonid(val) {
      console.log();
      this.carholder = val.id;
    },
    // 分页
    handleCurrentChange() {
      this.getweixiulist();
    },
    // 获取项目类型
    getitem() {
      const req = {
        handle:
          '67A5B6FEF17D97DECF116BDF95B95C0B167942DD3F1604F9',
        supid: '0301',
        codetype: '03',
      };
      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        if (ts.d.sflag == 'success') {
          this.itemdata = ts.d.data.operation1;
          // console.log(this.itemdata, "3");
        }
      });
    },
    // 获取维修列表
    getweixiulist() {
      const req = {
        handle:
          '0E56125B90D2898AECD50C1D5E36FA55E675CB75087360DC44B455B1B2775577',
        carrepairno: this.carrepairno,
        carno: this.carno,
        repairtype: this.repairtype,
        repairtimes: this.repairtime[0],
        repairtimee: this.repairtime[1],
        holder: this.holder,
        start: (this.pagobj.currentPage3 - 1) * this.pagobj.pagesize,
        limit: this.pagobj.pagesize,
      };
      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        if (ts.d.sflag == 'success') {
          this.carweixiulist = ts.d.data.operation1;
          this.pagobj.total = parseInt(ts.d.data.operation2[0].hash.allrs);
        }
      });
    },
  },
};
</script>

